/**
 * 学到了啥：
 * 1.StatefulWidget 组件，如果有状态管理，外面必须是这个组件
 * 2.++index 自增
 * 3.margin:Edgeinsets.only(bottom:0,top:0)
 * 4.图片引用  Image.asset()
 * 5.图片填充 fit:sizeBox.cover
 * 6.icon的使用 Icon(Icons.add)
*/
import 'package:flutter/material.dart';

class startPage extends StatefulWidget {
  final title;
  const startPage({ Key? key,required this.title }) : super(key: key);

  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<startPage> {
  List _imagName = [
    {
      'image':'assets/images/avatar.png','text':'岛上码农'
    },
    {
      'image':'assets/images/avatar.png','text':'扫码关注'
    }
  ];
  int _index = 0;
  void _onSwitch(){
    setState((){
      _index = (++ _index) % _imagName.length;
    });
    print('hello');
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Container(
          width: 300,
          height: 300,
          child: Column(
            children: [
              Container(
                width: 300,
                height: 300,
                child: Column(
                children: [
                  Container(
                    width: 128,
                    height: 128,
                    margin: EdgeInsets.only(top:10,bottom: 10),
                    child: Image.asset(
                      _imagName[_index]['image'],
                      fit: BoxFit.cover,
                    ),
                  ),
                  Text(_imagName[_index]['text'])
                ],           
                ),
              )
            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _onSwitch,
        tooltip: '切换',
        child: const Icon(Icons.swap_horizontal_circle_outlined),
      ),
    );
  }
}